﻿#include "BrowserTableHandlerSpectraAngularVelocity.h"

#include "OperatorsInterface/OperAbstractSpectra.h"

#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsSpectraManager.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbstractSpectra.h"

namespace GUI
{
    void BrowserTableHandlerSpectraAngularVelocity::updateData()
    {
        if (_spectraManager == nullptr || _tableWidget == nullptr)return;
        _tableWidget->setRowCount(0);

        QList<Acoustics::FITKAcousticsAbstractSpectra*> spectraList =
            _spectraManager->getSpectraByType(Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::AnlrVelocity);

        const int n = spectraList.size();
        _tableWidget->setRowCount(n);

        for (int i = 0; i < n; ++i)
        {
            Acoustics::FITKAcousticsAbstractSpectra* spectra = dynamic_cast<Acoustics::FITKAcousticsAbstractSpectra*>(spectraList.at(i));
            if (spectra == nullptr) continue;
            //数据ID
            const int id = spectra->getDataObjectID();
            //填充表格，用type表示ID
            QTableWidgetItem* item = new QTableWidgetItem(spectra->getDataObjectName(), id);
            item->setFlags(item->flags() & ~Qt::ItemIsEditable);
            _tableWidget->setItem(i, 0, item);
            item = new QTableWidgetItem(getBandWidth(spectra), id);
            item->setFlags(item->flags() & ~Qt::ItemIsEditable);
            _tableWidget->setItem(i, 1, item);
            item = new QTableWidgetItem(QString::number(spectra->getStartFreq()), id);
            item->setFlags(item->flags() & ~Qt::ItemIsEditable);
            _tableWidget->setItem(i, 2, item);
            item = new QTableWidgetItem(QString::number(spectra->getEndFreq()), id);
            item->setFlags(item->flags() & ~Qt::ItemIsEditable);
            _tableWidget->setItem(i, 3, item);
            item = new QTableWidgetItem(spectra->getNotes(), id);
            item->setFlags(item->flags() & ~Qt::ItemIsEditable);
            _tableWidget->setItem(i, 4, item);
        }
    }

    EventOper::OperAbstractSpectra * BrowserTableHandlerSpectraAngularVelocity::getSpectraOper()
    {
        //从操作器仓库获取
        return Core::FITKOperatorRepo::getInstance()->getOperatorT<EventOper::OperAbstractSpectra>("OperatorsSpectraAngularVelocity");
    }
}